﻿package com.ww_and_aloa.components.dropDown{
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class MenuItem extends Sprite{
		// Properties
		private var _value:String;
		private var txt:TextField=new TextField();
		private var txtFormat:TextFormat=new TextFormat();
		
		// Constructor
		public function MenuItem(caption:String,value:String,_width:int=200,_height:int=20):void{
			this.buttonMode=true;
			this.alpha=.8;
			_value=value;
			_width-=10;
			
			this.graphics.beginFill(0x000000);
			this.graphics.drawRect(0,0,_width,_height);
			
			txtFormat.color=0xFFFFFF;
			txtFormat.size=10;
			txtFormat.font="Verdana";
			
			txt.defaultTextFormat=txtFormat;			
			txt.mouseEnabled=false;
			txt.text=caption;
			txt.x=5;
			txt.y=2;
			txt.width=_width-10;
			txt.height=_height-4;
			addChild(txt);
			
			addEventListener(Event.ADDED_TO_STAGE,addedToStage);
			addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
			addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
		}
		
		private function mouseOver(e:MouseEvent):void{
			new TweenLite(this,1,{alpha:1});
		}
		
		private function mouseOut(e:MouseEvent):void{
			new TweenLite(this,1,{alpha:.8});
		}
		
		private function addedToStage(e:Event):void{
			this.y=this.parent.getChildIndex(this)*this.height;
		}
		
		public function get caption():String{
			return txt.text;
		}
		
		public function get value():String{
			return _value;
		}
	}
}